﻿using System;
using UnityEngine;

namespace KuiHuaBaoDian.Services.Audio {

    public interface IAudioModifier {

        public delegate void ChangedDelegate();
        event ChangedDelegate Changed;

        IAudioModifierSetter AsSetter();

        int Volume { get; }
    }

    public interface IAudioModifierSetter {

        void SetVolume(int volume);
    }

    [Serializable]
    public sealed class KHBD_AudioModifier : IAudioModifier, IAudioModifierSetter {

        public event IAudioModifier.ChangedDelegate Changed;

        [SerializeField]
        private int m_Volume;
        public int Volume => m_Volume;

        public IAudioModifierSetter AsSetter() => this;

        void IAudioModifierSetter.SetVolume(int volume) {
            m_Volume = volume;
            Changed?.Invoke();
        }
    }
}
